package com.coder.books.thinkinjava.arrays;

import com.coder.util.CountingGenerator;
import com.coder.util.Generator;
import com.coder.util.RandomGenerator;

/**
 * 生成器 测试类
 *
 * @author yuhushuan
 * @date 2020/8/13 19:16
 */
public class GeneratorsTest {
    public static int size = 10;

    public static void test(Class<?> surroundingClass) {
        for (Class<?> type : surroundingClass.getClasses()) {
            System.out.print(type.getSimpleName() + ": ");

            try {
                Generator<?> g = (Generator<?>) type.newInstance();
                for (int i = 0; i < size; i++){
                    System.out.print(g.next() + " ");
                }
                System.out.println();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) {
        test(CountingGenerator.class);
        test(RandomGenerator.class);
    }
}
